﻿package com.student.interceptor;

import java.util.Map;

import org.springframework.stereotype.Component;

import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
import com.student.model.Tuser;
import com.student.util.AuthorityCheck;


@Component("LoginInterception")
public class LoginInterception extends AbstractInterceptor{


	
		@Override
		public String intercept(ActionInvocation invocation) throws Exception {
			
			
//			System.out.println("invocation.getInvocationContext().getName()"+invocation.getInvocationContext().getName());
//			System.out.println("invocation.getProxy().getNamespace()"+invocation.getProxy().getNamespace());
			// TODO Auto-generated method stub
			ActionContext ctx = invocation.getInvocationContext();
			Map session = ctx.getSession();
			Tuser user=(Tuser)session.get("user");
			if(session.get("user")==null)
			{
				return "login";
			}else {
				AuthorityCheck authorityCheck=new  AuthorityCheck();
				if(authorityCheck.isAccess(user.getUserType().getTypeName(),invocation.getProxy().getNamespace(),invocation.getProxy().getActionName())){
					//能名被访问
					return invocation.invoke();
				}
				return "login";
			}
		}
		
}
